//
//  CNewsView.m
//  SinaWebo
//
//  Created by wwj on 16/7/7.
//  Copyright © 2016年 亦心. All rights reserved.
//

#import "CNewsView.h"
#import "ArticleHeadlineViewController.h"
#import "TitleViewController.h"
#import "ArticlePushAnimate.h"
#import "TitlePopAnimate.h"
#import "PageInfo.h"
#import "PageCard.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>

@interface CNewsView ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *pageTitle;
@property (weak, nonatomic) IBOutlet UIImageView *headliesFlash;
@property (weak, nonatomic) IBOutlet UILabel *contentLable;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imgH;

@property (strong, nonatomic) ArticlePushAnimate *pushAnimate;
@property (strong, nonatomic) TitlePopAnimate *popAnimate;
@end

@implementation CNewsView

+ (instancetype)newsView{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
}

- (ArticlePushAnimate *)pushAnimate{
    if (_pushAnimate == nil) {
        _pushAnimate = [[ArticlePushAnimate alloc] init];
    }
    return _pushAnimate;
}

- (TitlePopAnimate *)popAnimate{
    if (_popAnimate) {
        _popAnimate = [[TitlePopAnimate alloc] init];
    }
    return _popAnimate;
}

- (void)awakeFromNib{
    [super awakeFromNib];
    self.autoresizingMask = UIViewAutoresizingNone;
    _pageTitle.font = CardTitleLabelFont;
    
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickImage)];
    [self addGestureRecognizer:tapGR];
    
}


- (void)setPageInfo:(PageInfo *)pageInfo{
    _pageInfo = pageInfo;
    _imgH.constant = _pageInfo.typeNewImgH;
    self.pageTitle.text = _pageInfo.page_title;
    [_imageView sd_setImageWithURL:[NSURL URLWithString:_pageInfo.page_pic]];
    
    PageCard *pageCard = _pageInfo.cards.firstObject;
    self.contentLable.text = pageCard.content1;
}

- (void)onClickImage{
//    ArticleHeadlineViewController *articleVC = [[ArticleHeadlineViewController alloc] init];
//    articleVC.transitioningDelegate = self.popAnimate;
//    articleVC.modalPresentationStyle = UIModalPresentationCustom;
//    [DCURLRouter presentViewController:articleVC animated:nil completion:nil];
    
    TitleViewController *titleVC = [[TitleViewController alloc] init];
    titleVC.modalPresentationStyle = UIModalPresentationCustom;
    self.popAnimate.frame = CGRectMake((kScreenW - 180) * 0.5, 55, 180, 300);
    titleVC.transitioningDelegate = self.popAnimate;
    
     UIViewController *rootViewController =[UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *selection = [(UITabBarController *)rootViewController selectedViewController].childViewControllers.firstObject;
//    [DCURLRouter presentViewController:titleVC animated:nil completion:nil];
    [selection presentViewController:titleVC animated:YES completion:nil];
}

//- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source{
//    return [[UIPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];;
//}
//
//- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{
//    return 0.3;
//}
//
//- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
////    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
////    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
//    [transitionContext.containerView addSubview:_imageView];
//}



@end
